import java.time.LocalDateTime;

class Reception extends User {
    private Cinema cinema;

    public Reception(String username, String password) {
        super(username, password, "Reception");
        this.cinema = Cinema.getInstance();
    }

    public void viewSchedules() {
        System.out.println("当前排片:");
        for (Schedule schedule : cinema.getSchedules()) {
            System.out.println("- " + schedule);
        }
    }

    public void showSeats(String movieName, LocalDateTime time) {
        Schedule schedule = findSchedule(movieName, time);
        if (schedule != null) {
            schedule.getHall().showSeatsStatus();
        } else {
            System.out.println("未找到该排片");
        }
    }

    public boolean bookSeat(String movieName, LocalDateTime time, int row, int col, String customerName) {
        Schedule schedule = findSchedule(movieName, time);
        if (schedule == null) {
            System.out.println("未找到该排片");
            return false;
        }
        SeatMatrix<String> seatMatrix = schedule.getHall().getSeatMatrix();
        if (seatMatrix.reserveSeat(row, col, customerName)) {
            System.out.println("座位预订成功: 电影《" + movieName + "》" +
                    " 时间: " + time +
                    " 座位: " + (row + 1) + "排" + (col + 1) + "座");
            return true;
        }
        return false;
    }

    private Schedule findSchedule(String movieName, LocalDateTime time) {
        for (Schedule schedule : cinema.getSchedules()) {
            if (schedule.getMovie().getName().equals(movieName) &&
                    schedule.getTime().equals(time)) {
                return schedule;
            }
        }
        return null;
    }
}